<?php
/*
 * OpenSociax 核心入口文件
 * @author  dongheng <6347536@qq.com>
 * @version ST1.0
 */
if (!defined('SITE_PATH')) exit();
tsLoad('/core/CoreLib/ParamTools.class.php');
//取得封装的param(post和get融合一个方法)和取得封装的session
$param = new ParamTools();
tsLoad('/core/CoreLib/UserSessionTools.class.php');
$userSession = new UserSessionTools();

//开启缓存服务器
tsLoad('/core/CoreLib/RedisCluster.class.php');
//连接本地的 Redis 服务
$redis = new RedisCluster();
$redis->connect();


//根据收集的数据确认具体要载入的路径包常量
//收集所有响应参数
//取出所有参数
$action = isset($_GET['action'])?$_GET['action']:DEFAULT_PAGE;
$method = isset($_GET['method'])?$_GET['method']:$action;
$mod = isset($_GET['mod'])?$_GET['mod']:'manage';
$modelType = isset($_GET['modelType'])?$_GET['modelType']:'page';
$addons = isset($_GET['addons'])?$_GET['addons']:'';
$catalog = isset($_GET['catalog'])?$_GET['catalog']:'';


//如果是接口就不载入控制层
if($modelType=='service'){
    tsLoad('/service/'.$mod.'/'.$action.'.php');
    exit();
}

//开启debug工具包
tsLoad('/debug/ChromePhp.php');
//载入全局函数
tsLoad('/core/CoreLib/global.func.php');
//E_ALL 开启所有报错    0 关闭所有报错
error_reporting(E_ALL);

tsdefine('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());

$mtime = explode(' ', microtime());
$page_starttime = $mtime[1] + $mtime[0];

ini_set('magic_quotes_runtime', 0);
date_default_timezone_set('UTC');

$time_include_start = microtime(TRUE);
$mem_include_start = memory_get_usage();

//设置session保存时间
// 保存1小时
$lifeTime = 1 * 3600;
//session_set_cookie_params($lifeTime);
session_write_close();
ini_set('session.auto_start', 0);                 //关闭session自动启动
ini_set('session.cookie_lifetime', 0);            //设置session在浏览器关闭时失效
ini_set('session.gc_maxlifetime', $lifeTime);     //session在浏览器未关闭时的持续存活时间

//设置cookie工具
tsLoad('/include/CookieTools.class.php');
$cookieTools = new CookieTools();
$cookieTools->cookieCrossDomain();
//$cookieTools->setCookie('qiaoba', '123456',3600*60*60);

//session设置
//session_start();

if(PHP_VERSION < '4.1.0') {
    $_GET = &$HTTP_GET_VARS;
    $_POST = &$HTTP_POST_VARS;
    $_COOKIE = &$HTTP_COOKIE_VARS;
    $_SERVER = &$HTTP_SERVER_VARS;
    $_ENV = &$HTTP_ENV_VARS;
    $_FILES = &$HTTP_POST_FILES;
}

if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) {
    exit('Request 不能传glogals这样的参数.');
}

//define('ISROBOT', getrobot());
if(defined('NOROBOT') && ISROBOT) {
    exit(header("HTTP/1.1 403 Forbidden"));
}

//文件加上需要的斜杠/,防注入
if (!MAGIC_QUOTES_GPC && $_FILES) {
    $_FILES = daddslashes($_FILES);
}

//设置全局变量ts
$ts['_debug']	=	false;		//调试模式
$ts['_define']	=	array();	//全局常量
$ts['_config']	=	array();	//全局配置
$ts['_access']	=	array();	//访问配置
$ts['_router']	=	array();	//路由配置

tsdefine('IS_CGI',substr(PHP_SAPI, 0, 3)=='cgi' ? 1 : 0 );
tsdefine('IS_WIN',strstr(PHP_OS, 'WIN') ? 1 : 0 );
tsdefine('IS_HTTPS',0);
// 当前文件名
if(!defined('_PHP_FILE_')) {
	if(IS_CGI) {
		// CGI/FASTCGI模式下
		$_temp  = explode('.php',$_SERVER["PHP_SELF"]);
		define('_PHP_FILE_', rtrim(str_replace($_SERVER["HTTP_HOST"],'',$_temp[0].'.php'),'/'));
	}else {
		define('_PHP_FILE_', rtrim($_SERVER["SCRIPT_NAME"],'/'));
	}
}

// 网站URL根目录
if(!defined('__ROOT__')) {	
	$_root = dirname(_PHP_FILE_);
	define('__ROOT__',  (($_root=='/' || $_root=='\\')?'':rtrim($_root,'/')));
}

//基本常量定义
tsdefine('CORE_PATH'	,	dirname(__FILE__));
//网站域名不带HTTP
tsdefine('SITE_DOMAIN'	,	strip_tags($_SERVER['HTTP_HOST']));
//网站域名带HTTP
tsdefine('SITE_URL'		,	(IS_HTTPS?'https:':'http:').'//'.SITE_DOMAIN.__ROOT__.'/'.$mod);
tsdefine('SITE_GLOBAL_URL',	(IS_HTTPS?'https:':'http:').'//'.SITE_DOMAIN.__ROOT__);
//配置文件地址
tsdefine('CONF_PATH'	,	SITE_PATH.'/config');
//管理后台路径
tsdefine('MANAGE_PATH'	,	SITE_PATH.'/manage');
tsdefine('MANAGE_URL'	,	SITE_URL.'/manage');

//雨霏前台路径
tsdefine('YUFEI_PATH'	,	SITE_PATH.'/webyufei');
tsdefine('YUFEI_URL'    ,   SITE_URL.'/webyufei');

//tsdefine('UPLOAD_PATH'	,	DATA_PATH.'/upload');
//tsdefine('UPLOAD_URL'	,	SITE_URL.'/data/upload');

tsdefine('PUBLIC_PATH'	,	SITE_PATH.'/public');
tsdefine('PUBLIC_URL'	,	SITE_URL.'/public');

//载入核心模式: 默认是OpenSociax. 也支持ThinkPHP
if(!defined('CORE_MODE'))	define('CORE_MODE','CoreLib');
tsdefine('CORE_LIB_PATH'	,	CORE_PATH.'/'.CORE_MODE);
tsdefine('CORE_RUN_PATH'	,	SITE_PATH.'/_runtime');
tsdefine('LOG_PATH'			,	CORE_RUN_PATH.'/logs/');

//载入数据库工具
tsLoad('/core/CoreLib/MysqlTools.class.php');
//载入核心action类
tsLoad('/core/CoreLib/Action.class.php');
//载入检验类
tsLoad('/core/CoreLib/Validate.class.php');
//引入数据库配置
$config	=	require(SITE_PATH.'/config/config.inc.php');
//全局数据库操作对象
$mysqlTools = new MysqlTools($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'],$config['DB_PORT']);
//建立连接
$conn = $mysqlTools->createConnect();
//************************************************mongo数据库操作连接 ********************************************
//$mongoTools = new Mongo("mongodb://127.0.0.1:27017"); // Connect to Mongo Server
//$admin = $mongoTools->admin; // Connect to Database

//$product_type = $admin->product_type;
//$productTypes = $product_type->find();
//var_dump($productTypes->count());
//***********************************************************************************************************     

/* var_dump($mod);
var_dump($modelType);
var_dump($addons);
var_dump($action);
var_dump($method); **/

/***************************************************************************************************************
 *********************************根据url地址访问不同的文件************************************************************** 
 *****************************************************************************************************************/
//获取域名或主机地址
$httpHost = $_SERVER['HTTP_HOST'];      //获取网页地址(中间部分)
$httpVars = $_SERVER['PHP_SELF'];       //真实访问文件地址
$httpQueryString = $_SERVER["QUERY_STRING"];     //获取地址?后的参数
$httpRequestUrl = $_SERVER['REQUEST_URI'];       //用户访问地址
$httpFullUrl = 'http://'.$httpHost.$httpRequestUrl;        //用户访问全地址

//5.3后explode代替split
$httpRequestUrlArray = explode('[?.-]', $httpRequestUrl);
if(!empty($httpRequestUrlArray) && count($httpRequestUrlArray)>=1)
    $httpRealPageUrl = $httpRequestUrlArray[0];
else
    $httpRealPageUrl = $httpRequestUrl;
//我们看到的('/^http:\/\/([\w.]+)\/([\w]+)\/([\w]+)\.html/i')中的最后一个"i"就是修饰符,表示忽略大小写，还有一个我们经常用到的是"x"表示忽略空格。
//$regex = '#^/([\w.]+)$#i';

tsdefine('REQUEST_URL',$httpRequestUrl);
$onlineip=$_SERVER['REMOTE_ADDR'];

$httpHostArray = explode('[..-]', $httpHost);
/* if(count($httpHostArray)>=3){
    if($httpHostArray[0]=='manage')$mod = 'manage';
} */
/***********************************************************************************************************************/

/***************************************************************************************************************
 *********************************缓存读取写入套件**************************************************************
*****************************************************************************************************************/
//页面缓存机制索引
tsLoad('/core/CoreLib/WebCacheTools.class.php');
$webCacheTools = new WebCacheTools();
$webCacheTools->readWebCache($httpRealPageUrl);
//***************************************************************************************************************
//如果没有读取到静态的页面就开始捕捉  以后最好根据具体地址来捕捉
$webCacheTools->startCatch($httpRealPageUrl);
if(!defined('IS_SERVICE')){
    //调用控制层的方法
    tsExecuteAction($mod,$modelType,$addons,$action,$method,$catalog);
}
//在文件读完后判断是否加入缓存
$webCacheTools->writeWebCache($httpRealPageUrl);

$time_include_end = microtime(TRUE);
//查看时间差
//var_dump(($time_include_end-$time_include_start));
/* 核心方法 */
/**
 * 载入文件 去重\缓存.
 * @param string $filename 载入的文件名
 * @return boolean
 */
function tsLoad($filename) {
	static $_importFiles = array();	//已载入的文件列表缓存
	$key = strtolower($filename);
	
	if (!isset($_importFiles[$key])) {
		if (is_file($filename)) {
			require_once $filename;
			$_importFiles[$key] = true;
		} elseif(file_exists(SITE_PATH.$filename)) {
			require_once SITE_PATH.$filename;
			$_importFiles[$key] = true;
		} else {
			$_importFiles[$key] = false;
		}
	}
	return $_importFiles[$key];
}

function tsInclude($url){
    include(SITE_GLOBAL_URL.$url);
}

/**
 * 执行action
 * @param string $mod   子项目名
 * @param string $modelType    模型名
 * @param string $action    action名
 * @param string $method       方法名
 * @param string $returnType    返回类型
 */
function tsExecuteAction($mod,$modelType,$addons,$action,$method,$catalog){
	if(isset($catalog) && $catalog!='') $catalog = $catalog.'/';
    if(isset($addons) && $addons!='') $addons = $addons.'/';
    $actionClass = ucfirst($action).'Action';
    $action = ucfirst($action).'Action.class.php';
    $accessActionPath = '/'.$mod.'/'.$modelType.'/'.$catalog.$addons.$action;
    $accessPath = '/'.$mod.'/'.$modelType.'/'.$catalog.$addons.$method.'View.php';
    //载入包中
    tsLoad($accessActionPath);
    
    $$actionClass = new $actionClass();
    //执行初始化操作
    call_user_func(array(&$$actionClass,'init'));
    //执行当前操作
    $returnType = call_user_func(array(&$$actionClass,$method));
    if(!isset($returnType))$returnType='html';
    
    //取出所有参数
    $tVar = call_user_func(array(&$$actionClass,'getAllVar'));
    
    if($returnType!='smarty')header("Content-Type:text/html; charset=utf-8");
    switch ($returnType){
        case 'html':
            global $config;
            
            $_REQUEST = $tVar;
            $_REQUEST['charset'] = $config['CHARSET'];
            //如果定义了同目录其他变量就重组地址
            if(isset($tVar['view']))
                $accessPath = '/'.$mod.'/'.$modelType.'/'.$catalog.$addons.$tVar['view'].'View.php';
            //如果定义了全局地址就重组全局地址
            if(isset($tVar['viewfull']))
                $accessPath = $tVar['viewfull'].'View.php';
            
            if(file_exists(SITE_PATH.$accessPath))
                tsLoad($accessPath);
            break;
        case 'json':
        	//判断是否有要求权限,如果有就进行权限效验
        	if(isset($tVar['validateMenuJuri']) && $tVar['validateMenuJuri']==true){
        		if(!validateMethod()){
        			echo urldecode(json_encode(url_encode(array("result"=>false,"reason"=>"您的权限不够或您还没有登录或登录过期请重试！"))));
        			exit;
        		}
        	}
            echo urldecode(json_encode(url_encode($tVar)));
            break;
        case 'xml':
            echo xml_encode($tVar);
            break;
        case 'js':
            // 返回可执行的js脚本
            if(!isset($tVar['data'])) {
                $tVar['data']='';
            }
            echo $tVar['data'];
        default:
        	$smarty = call_user_func(array(&$$actionClass,'getSmarty'));
        	//判断是否有要求权限,如果有就进行权限效验
        	if(isset($tVar['validateMenuJuri']) && $tVar['validateMenuJuri']==true){
        		if(!validateMethod()){
        			smartyDisplay($smarty,'/manage/page/login/login.html');
        			exit;
        		}
        	}
        	if(isset($tVar['smarty'])){
        		smartyDisplay($smarty,$tVar['smarty']);
        	}
            break; 
    }
    global $mysqlTools;
    //释放连接
    $mysqlTools->closeConnect();
}

/**
 * 效验方法权限方法
 */
function validateMethod(){
	//效验权限一定是登录状态所以必须登录有信息的才能效验
	global $userSession,$param;
	$params = $param->getParams();
	$userInfo = $userSession->getUserSession();
	 
	if(empty($userInfo))return false;
	else {
		//效验他的权限
		$method = $param->get("method");
		tsLoad('/manage/busi/SysUserBusi.class.php');
		$sysUserBusi = new SysUserBusi();
		$result = $sysUserBusi->queryUserVisitMenuIsPass(array(
				"userId"=>$userSession->getUserSession()["userId"],
				"method"=>$method
		));
		return $result;
	}
}

/**
 * 定义常量,判断是否未定义.
 *
 * @param string $name 常量名
 * @param string $value 常量值
 * @return string $str 返回常量的值
 */
function tsdefine($name,$value) {
	global $ts;
	//定义未定义的常量
	if(!defined($name)){
		//定义新常量
		define($name,$value);
	}else{
		//返回已定义的值
		$value = constant($name);
	}
	//缓存已定义常量列表
	$ts['_define'][$name] = $value;
	return $value;
}

/**
 * 返回16位md5值
 *
 * @param string $str 字符串
 * @return string $str 返回16位的字符串
 */
function tsmd5($str) {
	return substr(md5($str),8,16);
}

/**
 * 载入配置 修改自ThinkPHP:C函数 为了不与tp冲突
 *
 * @param string $name 配置名/文件名.
 * @param string|array|object $value 配置赋值
 * @return void|null
 */
function tsconfig($name=null,$value=null) {
    global $ts;
    // 无参数时获取所有
    if(empty($name)) return $ts['_config'];
    // 优先执行设置获取或赋值
    if (is_string($name))
    {
        if (!strpos($name,'.')) {
            $name = strtolower($name);
            if (is_null($value))
                return isset($ts['_config'][$name])? $ts['_config'][$name] : null;
            $ts['_config'][$name] = $value;
            return;
        }
        // 二维数组设置和获取支持
        $name = explode('.',$name);
        $name[0]   = strtolower($name[0]);
        if (is_null($value))
            return isset($ts['_config'][$name[0]][$name[1]]) ? $ts['_config'][$name[0]][$name[1]] : null;
        $ts['_config'][$name[0]][$name[1]] = $value;
        return;
    }
    // 批量设置
    if(is_array($name))
        return $ts['_config'] = array_merge((array)$ts['_config'],array_change_key_case($name));
    return null;// 避免非法参数
}

/**
 * 执行钩子方法
 *
 * @param string $name 钩子方法名.
 * @param array $params 钩子参数数组.
 * @return array|string Stripped array (or string in the callback).
 */
function tshook($name,$params=array()) {
	global $ts;
    $hooks	=	$ts['_config']['hooks'][$name];
    if($hooks) {
        foreach ($hooks as $call){
            if(is_callable($call))
                $result = call_user_func_array($call,$params);
        }
        return $result;
    }
    return false;
}

/**
 * Navigates through an array and removes slashes from the values.
 *
 * If an array is passed, the array_map() function causes a callback to pass the
 * value back to the function. The slashes from this value will removed.
 * @param array|string $value The array or string to be striped.
 * @return array|string Stripped array (or string in the callback).
 */
function stripslashes_deep($value) {
	if ( is_array($value) ) {
		$value = array_map('stripslashes_deep', $value);
	} elseif ( is_object($value) ) {
		$vars = get_object_vars( $value );
		foreach ($vars as $key=>$data) {
			$value->{$key} = stripslashes_deep( $data );
		}
	} else {
		$value = stripslashes($value);
	}
	return $value;
}

/**
 * GPC参数过滤
 * @param array|string $value The array or string to be striped.
 * @return array|string Stripped array (or string in the callback).
 */
function check_gpc($value=array()) {
	if(!is_array($value)) return;
	foreach ($value as $key=>$data) {
		//对get、post的key值做限制,只允许数字、字母、及部分符号_-[]#@~
		if(!preg_match('/^[a-zA-z0-9,_\-#!@~\[\]]+$/i',$key)){
			die('wrong_parameter: not safe get/post/cookie key.');
		}
		//如果key值为app\mod\act,value只允许数字、字母下划线
		if( ($key=='app' || $key=='mod' || $key=='act') && !empty($data) ){
			if(!preg_match('/^[a-zA-z0-9_]+$/i',$data)){
				die('wrong_parameter: not safe app/mod/act value.');				
			}
		}
	}
}

//全站静态缓存,替换之前每个model类中使用的静态缓存
//类似于s和f函数的使用
function static_cache($cache_id,$value=null,$clean = false){
    static $cacheHash = array();
    if($clean){ //清空缓存 其实是清不了的 程序执行结束才会自动清理
        unset($cacheHash);
        $cacheHash = array(0);
        return $cacheHash;
    }
    if(empty($cache_id)){
        return false;
    }
    if($value === null){
        //获取缓存数据
        return isset($cacheHash[$cache_id]) ? $cacheHash[$cache_id] : false;
    }else{
        //设置缓存数据
        $cacheHash[$cache_id] = $value;
        return $cacheHash[$cache_id];
    }
}

//取得基础CSS和JS
function getCommon(){
    echo '<script>';
    echo 'var _hmt = _hmt || [];';
    echo '(function() {';
    echo '    var hm = document.createElement("script");';
    echo '    hm.src = "//hm.baidu.com/hm.js?2ca01081c9f5cb456c965adefba44460";';
    echo '    var s = document.getElementsByTagName("script")[0];';
    echo '    s.parentNode.insertBefore(hm, s);';
    echo '})();';
    echo '</script>';
    
    echo '<link href="'.SITE_GLOBAL_URL.'/css/common/global.css'.'" rel="stylesheet" type="text/css" />';
    echo '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/js/common/jquery-2.2.1.min.js"></script>';
    echo '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/js/common/jquery-browser.js"></script>';
    echo '<link rel="icon" href="'.SITE_GLOBAL_URL.'/images/common/cqtao.ico" type="image/x-icon" />';
}

//取得页面JS地址
function getPageJs($url){
    echo '<script type="text/javascript" src="'.SITE_URL.'/js/page/'.$url.'"></script>';
}

//取得页面CSS地址
function getPageCss($url){
    echo '<link href="'.SITE_URL.'/style/page/'.$url.'" rel="stylesheet" type="text/css" />';
}

//取得模块JS地址
function getModuleJs($url){
    echo '<script type="text/javascript" src="'.SITE_URL.'/js/module/'.$url.'"></script>';
}

//取得模块CSS地址
function getModuleCss($url){
    echo '<link href="'.SITE_URL.'/style/module/'.$url.'" rel="stylesheet" type="text/css" />';
}

//取得模板JS地址
function getTemplateJs($url){
    echo '<script type="text/javascript" src="'.SITE_URL.'/js/template/'.$url.'"></script>';
}

//取得模板CSS地址
function getTemplateCss($url){
    echo '<link href="'.SITE_URL.'/style/template/'.$url.'" rel="stylesheet" type="text/css" />';
}

/**
 * 取得插件路径
 * @param unknown $plusArray
 * @return string
 */
function getPlug($plusArray){
    $plusHtml = '';
    foreach ($plusArray as $i => $plus)
        switch($plus){
        //异步上传插件
            case 'AjaxFileUploader':
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ajaxFileUpload/ajaxFileUpload.js"></script>';
                break;
                //flash异步多文件上传插件
            case 'uploadify':
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uploadify/jquery.uploadify.min.js"></script>';
                $plusHtml .= '<link href="'.SITE_URL.'/plug/uploadify/uploadify.css" rel="stylesheet" type="text/css" />';
                break;
            case 'ueditor':
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ueditor/ueditor.config.js"></script>';
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ueditor/ueditor.all.js"></script>';
                break;
            case 'uiDialog':
                $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiDialog/css/uiDialog.css" rel="stylesheet" type="text/css" />';
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiDialog/uiDialog.js"></script>';
                break;
            case 'belatedPNG':
                $plusHtml .= '<!--[if IE 6]>';
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/belatedPNG/DD_belatedPNG.js"></script>';
                $plusHtml .= '<script>';
                $plusHtml .= 'DD_belatedPNG.fix(\'.png_bg,.png-bg\');';
                $plusHtml .= '</script>';
                $plusHtml .= '<![endif]-->';
                break;
            case 'wdatePicker':
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/My97DatePicker/WdatePicker.js"></script>';
                break;
            case 'ztree':
                $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />';
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ztree/js/jquery.ztree.all-3.5.min.js"></script>';
                break;
            case 'uiGrid':
                $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiGrid/css/ui_grid.css" rel="stylesheet" type="text/css" />';
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiGrid/ui_grid.js"></script>';
                break;
            case 'lazyload':
                $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/lazyload/jquery.lazyload.js"></script>';
                break;
            case 'uiSelect':
            	$plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiSelect/css/ui_select.css" rel="stylesheet" type="text/css" />';
            	$plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiSelect/js/ui_select.js"></script>';
            	break;
            default:
                break;
        }
    return $plusHtml;
}

/**
 * 取得插件路径
 * @param unknown $plusArray
 * @return string
 */
function getPlugSingle($plus){
    $plusHtml = '';
    switch($plus){
        //异步上传插件
        case 'AjaxFileUploader':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ajaxFileUpload/ajaxFileUpload.js"></script>';
            break;
            //flash异步多文件上传插件
        case 'uploadify':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uploadify/js/jquery.uploadify.js"></script>';
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uploadify/css/uploadify.css" rel="stylesheet" type="text/css" />';
            break;
        case 'ueditor':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ueditor/ueditor.config.js"></script>';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ueditor/ueditor.all.js"></script>';
            break;
        case 'uiDialog':
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiDialog/css/uiDialog.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiDialog/uiDialog.js"></script>';
            break;
        case 'belatedPNG':
            $plusHtml .= '<!--[if IE 6]>';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/belatedPNG/DD_belatedPNG.js"></script>';
            $plusHtml .= '<script>';
            $plusHtml .= 'DD_belatedPNG.fix(\'.png_bg,.png-bg\');';
            $plusHtml .= '</script>';
            $plusHtml .= '<![endif]-->';
            break;
        case 'wdatePicker':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/My97DatePicker/WdatePicker.js"></script>';
            break;
        case 'ztree':
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ztree/js/jquery.ztree.core.js"></script>';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ztree/js/jquery.ztree.excheck.js"></script>';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/ztree/js/jquery.ztree.exedit.js"></script>';
            break;
        case 'uiGrid':
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiGrid/css/ui_grid.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiGrid/ui_grid.js"></script>';
            break;
        case 'audioPlay':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/common/jquery-audioPlay.js"></script>';
            break;
        case 'lazyload':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/lazyload/jquery.lazyload.js"></script>';
            break;
        case 'uiSelect':
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/uiSelect/css/ui_select.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/uiSelect/js/ui_select.js"></script>';
            break;
        case 'easyui':
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/jquery-easyui-1.4.4/themes/metro/easyui.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<link href="'.SITE_GLOBAL_URL.'/plug/jquery-easyui-1.4.4/themes/icon.css" rel="stylesheet" type="text/css" />';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>';
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>';
            break;
        case 'cookie':
            $plusHtml .= '<script type="text/javascript" src="'.SITE_GLOBAL_URL.'/plug/cookie/cookie.js"></script>';
            break;
        default:
            break;
    }
    echo $plusHtml;
}

//取得临时图片路径
function getCommonImgUrl(){
    echo SITE_GLOBAL_URL.'/images/common/';
}

//smarty模板显示情况
function smartyDisplay($smarty,$url){
    $smarty->display(SITE_PATH.$url);
}

//判断用户是否登录效验
function validateLogin(){
	
}

function url_encode($str) {
	if(is_array($str)) {
		foreach($str as $key=>$value) {
			$str[urlencode($key)] = url_encode($value);
		}
	} else {
		$str = urlencode($str);
	}

	return $str;
}
?>